#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
import time
#import urllib
import urllib2

def useage():
    if not len(sys.argv)>1:
        print "Place input you stock code"
        print "Example: python stock_price.py sz000996"
        sys.exit(0)
    
if __name__ == "__main__":
    useage()
    url = "http://hq.sinajs.cn/list="+sys.argv[1]
    sp = ' | '
    req = urllib2.Request(url)
    price_old = 0
    while True:
        res_data = urllib2.urlopen(req)
        res = res_data.read()
        price = res.split(',')
        if price[3] > price_old:
            trend = '+'
        elif price[3] == price_old:
            trend = ' '
        else:
            trend = '-'
        price_old = price[3]
        print price[3],trend,sp,price[31]
        time.sleep(5)